<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>BJCA</title>
  <style type="text/css">
  </style>
  <link href="/static/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table width="957" border="0" align="center" cellpadding="0"
       cellspacing="0">
  <tr>
    <td height="60">
      <img src="/static/images/logo.gif" width="245" height="38" />
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <table width="957" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="64"><img src="/static/images/z1.gif" width="64" height="221" /></td>
          <td width="304"><img src="/static/images/z2.gif" width="304" height="221" /></td>
          <td width="338"><img src="/static/images/z3.gif" width="338" height="221" /></td>
          <td><img src="/static/images/z4.gif" width="251" height="221" /></td>
        </tr>
        <tr>
          <td valign="top"><img src="/static/images/m1.gif" width="64" height="151" /></td>
          <td valign="top"><img src="/static/images/m2.gif" width="304" height="151" /></td>
          <td valign="top" height="151">
            <form method="post" ID="LoginForm" name="LoginForm" onsubmit="return LoginForm_onsubmit()">
              <table id="bs" width="90%" border="0" align="center"
                     cellpadding="0" cellspacing="0">
                <tr>
                  <td height="15" colspan="2"></td>
                </tr>
                <tr>
                  <td width="90" class="font1">
                    选择证书
                  </td>
                  <td>
                    <select id="UserList" name="UserList"></select>
                  </td>
                </tr>
                <tr>
                  <td >
                    &nbsp;
                  </td>
                  <td>
                    &nbsp;
                  </td>
                </tr>
                <tr>
                  <td class="font1">
                    证书密码
                  </td>
                  <td>
                    <input type="password" name="pwd1" id="UserPwd" size="16" maxlength="16">
                  </td>
                </tr>
                <tr>
                  <td >
                    <input type="text" style="display: none" name="userSF" id="userSF" size="16" maxlength="16">
                  </td>
                  <td>
                    &nbsp;
                  </td>
                </tr>
                <tr>
                  <td width="65">
                    <input type="submit"
                           style="border: none; background: url(/static/images/submit.gif) left top no-repeat; width: 58px; height: 30px;"
                           value="" name="B1">
                  </td>
                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="register">去注册 </a>

                  </td>


                </tr>
              </table>
              <!--              <input type="hidden" ID="UserSignedData" name="UserSignedData">-->
              <!--              <input type="hidden" ID="UserCert" name="UserCert">-->
              <!--              <input type="hidden" ID="ContainerName" name="ContainerName">-->
              <input type="hidden" ID="strRandom" name="strRandom">


              <div id="span1"  style="display: none" th:text="${session.strServerCert}"></div>
              <div id="span2"  style="display: none"  th:text="${session.strRandom}"></div>
              <div id="span3"  style="display: none"  th:text="${session.strSignedData}"></div>

            </form>
          </td>
          <td valign="top"><img src="/static/images/m4.gif" width="251" height="151" /></td>
        </tr>
        <tr>
          <td><img src="/static/images/b1.gif" width="64" height="20" /></td>
          <td><img src="/static/images/b2.gif" width="304" height="20" /></td>
          <td><img src="/static/images/b3.gif" width="338" height="20" /></td>
          <td><img src="/static/images/b4.gif" width="251" height="20" /></td>
        </tr>
        <tr>
          <td colspan="4" height="110"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>

</body>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
  var strServerCert= document.getElementById("span1").innerHTML;
  var strServerRan =  document.getElementById("span2").innerHTML;
  var strServerSignedData = document.getElementById("span3").innerHTML;

  console.log("服务端对随机数签名值："+strServerSignedData)
  // alert("服务端签名："+strServerSignedData)
  console.log("服务端产生随机数："+strServerRan)
  console.log("服务端证书："+strServerCert)

  function verifyCertServe(strServerCert,strServerRan,strServerSignedData){
    VerifySignedData(strServerCert,strServerRan,strServerSignedData,function (result){
      console.log("验证服务端结果："+result.retVal)
    })
  }
  var userCert="";
  var userSF="";
  //获取用户实体唯一标识
  function getUserCert(){
    GetSignCert(LoginForm.UserList.value,function (certobj){
      console.log("客户端cert"+certobj.retVal)
      userCert=certobj.retVal;
    })

  }
  function getUserEnity(){
    GetCertEntity(userCert,function (obj){
      console.log("客户端cert"+userCert)
      console.log("用户唯一实体标识"+obj.retVal)

      userSF=obj.retVal;
      document.getElementById("userSF").value=obj.retVal;
    },2)
  }

  function LoginForm_onsubmit() {
    //获取用户证书
    getUserCert();
    //获取用户实体唯一标识
    getUserEnity();

    verifyCertServe(strServerCert,strServerRan,strServerSignedData);
    var strCertID =  LoginForm.UserList.value;
    var strPin = LoginForm.UserPwd.value;
    LoginForm.strRandom.value = strServerRan;

    Login("LoginForm", strCertID, strPin, "login.jsp?certid="+strCertID);
    return false;
  }


</SCRIPT>
<SCRIPT type="text/javascript" src="/static/XTXSAB.js" charset="UTF-8"></SCRIPT>
<SCRIPT LANGUAGE=JAVASCRIPT>
  SetUserCertList("LoginForm.UserList", CERT_TYPE_HARD);
</SCRIPT>
</html>
